const puppeteer = require('puppeteer');
const MongoClient = require('mongodb').MongoClient;
const ObjectId = require('mongodb').ObjectId;


async function main() {
  const url = "mongodb://taosha_user:apyl8XWP6LSW4JHs@101.35.6.34:27722/taosha";
  const client = await MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
  const db = client.db('taosha');


  let topics = await db.collection('topics')
    .find({content: /\[b/, author_name: '博海拾贝'})
    .sort({_id: 1}).skip(0).limit(1000)
    .toArray();

  let len = topics.length;

  for (let i = 0; i < topics.length; i++) {
    let topic = topics[i];

    let content = topic.content.replace(/\\\[b\\\]/, '').trim();

    let result = await db.collection('topics').updateOne({_id: topic._id}, {
      $set: {
        content, content
      }
    });
    console.log(topic.title, result.modifiedCount, i, len);
  }


}

main();
